﻿<?xml version="1.0" encoding="utf-8"?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="KanbanBoard.Server.Command.DomainModel" assembly="KanbanBoard.Server.Command.DomainModel" default-lazy="false" default-cascade="all" default-access="field">
  <class name="TaskBoard">
    <id type="int">
      <generator class="native" />
    </id>
    <set name="columns">
      <key column="TaskBoardId" />
      <one-to-many class="Column" />
    </set>
    <set name="lanes">
      <key column="TaskBoardId" />
      <one-to-many class="Lane" />
    </set>
  </class>

  <class name="Column" table="[Column]">
    <id type="int">
      <generator class="native" />
    </id>
    <set name="tasks">
      <key column="ColumnId" />
      <one-to-many class="Task" />
    </set>    
  </class>

  <class name="Lane">
    <id type="int">
      <generator class="native" />
    </id>
    <set name="tasks">
      <key column="LaneId" />
      <one-to-many class="Task" />
    </set>
  </class>

  <class name="Task">
    <id type="int">
      <generator class="native" />
    </id>
    <property name="description" />
    <many-to-one name="priority" column="PriorityId" />
    <many-to-one name="column" column="ColumnId" />
    <many-to-one name="lane" column="LaneId" />
  </class>

  <class name="Priority" discriminator-value="normal">
    <id type="int">
      <generator class="native" />
    </id>

    <discriminator formula="CASE WHEN HigherPriorityId IS NULL THEN 'highest' ELSE 
                            CASE WHEN LowerPriorityId IS NULL THEN 'lowest' 
                            ELSE 'normal' END END" />

    <many-to-one name="higher" column="HigherPriorityId" />
    <many-to-one name="lower" column="LowerPriorityId" />
    <property name="numericPriority" />

    <subclass name="Priority+HighestPriority" discriminator-value="highest" />
    <subclass name="Priority+LowestPriority" discriminator-value="lowest" />
  </class>
</hibernate-mapping>